<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item prop="patientCode">
        <el-input
          v-model="queryParams.patientCode"
          placeholder="请输入或扫码病案号"
          size="medium"
          style="width: 402px"
          suffix-icon="el-icon-menu"
          ref="patientCodeRef"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <br />
      <el-form-item prop="diagnoseCreatedAt">
        <el-date-picker clearable size="small" style="width: 194px"
          v-model="queryParams.diagnoseCreatedAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="处方建立时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item prop="synTime">
        <el-date-picker clearable size="small" style="width: 194px"
          v-model="queryParams.synTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="最后更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item prop="doctorCode">
        <el-input
          v-model="queryParams.doctorName"
          placeholder="医生"
          clearable
          size="small"
          suffix-icon="el-icon-menu"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="isEquipStr">
        <el-select v-model="queryParams.isEquipStr" placeholder="是否配货" size="small" multiple clearable>
          <el-option label="未配货" :value="0" />
          <el-option label="已配货" :value="1" />
          <el-option label="部分配货" :value="2" />
          <el-option label="超配" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item prop="isSendStr">
        <el-select v-model="queryParams.isSendStr" placeholder="是否发药" size="small" multiple clearable>
          <el-option label="未发药" :value="0" />
          <el-option label="已发药" :value="1" />
          <el-option label="部分发药" :value="2" />
          <el-option label="超发" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item prop="isBillStr">
        <el-select v-model="queryParams.isBillStr" placeholder="是否结账" size="small" multiple clearable>
          <el-option label="未结账" :value="0" />
          <el-option label="已结账" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item prop="encounterId">
        <el-input
          v-model="queryParams.encounterId"
          placeholder="就诊号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="deptIds">
        <div class="mod-selectTree-wrap">
          <treeselect
            v-model="queryParams.deptIds"
            :multiple="true"
            :options="deptOptions"
            :value-consists-of="valueConsistsOf"
            placeholder="开单诊所"
          />
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="success" icon="el-icon-upload2" size="mini" @click="saveQuery">保存查询条件</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['sundry:head:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['sundry:head:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['sundry:head:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sundry:head:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="headList" @selection-change="handleSelectionChange">
      <el-table-column label="处方建立时间" align="center" prop="diagnoseCreatedAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.diagnoseCreatedAt) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后更新时间" align="center" prop="synTime" width="180">
        <template slot-scope="scope">
          <span class="font-error-color" v-if="new Date(scope.row.synTime) >= new Date(scope.row.auditorTime)">{{ parseTime(scope.row.synTime) }}</span>
          <span v-else>{{ parseTime(scope.row.synTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="顾客姓名" align="center" prop="patientName" />
      <el-table-column label="病案号" align="center" prop="patientCode" />
      <el-table-column label="就诊号" align="center" prop="encounterId" />
      <el-table-column label="医生" align="center" prop="doctorName" />
      <el-table-column label="开单诊所" align="center" prop="deptName" />
      <el-table-column label="是否完成发货" align="center" prop="isSend">
        <template slot-scope="scope">
          <span v-if="scope.row.isSend === 0">否</span>
          <span class="font-error-color" v-else-if="scope.row.auditStatus !== 1 && scope.row.isSend === 1">是</span>
          <span class="font-error-color" v-else-if="scope.row.auditStatus !== 1 && scope.row.isSend === 2">部分发</span>
          <span v-else-if="scope.row.isSend === 1">是</span>
          <span v-else-if="scope.row.isSend === 2">部分发</span>
          <span class="font-error-color" v-else-if="scope.row.isSend === 3">超发</span>
          <span v-else>N/A</span>
        </template>
      </el-table-column>
      <el-table-column label="是否结账" align="center" prop="isBill">
        <template slot-scope="scope">
          <span v-if="scope.row.isBill === 0">否</span>
          <span v-else-if="scope.row.isBill === 1">是</span>
          <span v-else>N/A</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.auditStatus === 1"
            size="mini"
            type="text"
            @click="handleSend(scope.row)"
          >发货</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改处方单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="630px">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="处方单号" prop="diagnoseId">
          <el-input v-model="form.diagnoseId" placeholder="请输入处方单号" />
        </el-form-item>
        <el-form-item label="单据类型，1 处方 2 杂项">
          <el-select v-model="form.orderType" placeholder="请选择单据类型，1 处方 2 杂项">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="就诊号" prop="encounterId">
          <el-input v-model="form.encounterId" placeholder="请输入就诊号" />
        </el-form-item>
        <el-form-item label="hms处方Id" prop="diagnoseCode">
          <el-input v-model="form.diagnoseCode" placeholder="请输入hms处方Id" />
        </el-form-item>
        <el-form-item label="处方建立时间" prop="diagnoseCreatedAt">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.diagnoseCreatedAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择处方建立时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="开单诊所" prop="deptCode">
          <el-input v-model="form.deptCode" placeholder="请输入开单诊所" />
        </el-form-item>
        <el-form-item label="诊所名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入诊所名称" />
        </el-form-item>
        <el-form-item label="医生编码" prop="doctorCode">
          <el-input v-model="form.doctorCode" placeholder="请输入医生编码" />
        </el-form-item>
        <el-form-item label="医生" prop="doctorName">
          <el-input v-model="form.doctorName" placeholder="请输入医生" />
        </el-form-item>
        <el-form-item label="病案号" prop="patientCode">
          <el-input v-model="form.patientCode" placeholder="请输入病案号" />
        </el-form-item>
        <el-form-item label="顾客姓名" prop="patientName">
          <el-input v-model="form.patientName" placeholder="请输入顾客姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="出生日期" prop="dob">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dob"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核人ID" prop="auditorId">
          <el-input v-model="form.auditorId" placeholder="请输入审核人ID" />
        </el-form-item>
        <el-form-item label="最后审核人" prop="auditorName">
          <el-input v-model="form.auditorName" placeholder="请输入最后审核人" />
        </el-form-item>
        <el-form-item label="最后审核时间" prop="auditorTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.auditorTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择最后审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="form.auditStatus" placeholder="状态" size="small" clearable>
            <el-option label="未审核" :value="0" />
            <el-option label="审核通过" :value="1" />
            <el-option label="审核未通过" :value="2" />
            <el-option label="重新审核" :value="3" />
            <el-option label="无需审核" :value="4" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否需要审核" prop="isAudit">
          <el-select v-model="form.isAudit" placeholder="是否需要审核" size="small" clearable>
            <el-option label="不需要审核" :value="0" />
            <el-option label="需要审核" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="审核内容" prop="auditContent">
          <el-input v-model="form.auditContent" placeholder="请输入审核内容" />
        </el-form-item>
        <el-form-item label="是否配货" prop="isEquip">
          <el-select v-model="form.isEquip" placeholder="是否配货" size="small" clearable :disabled="isUpdate">
            <el-option label="未配货" :value="0" />
            <el-option label="已配货" :value="1" />
            <el-option label="部分配货" :value="2" />
            <el-option label="超配" :value="3" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否发货" prop="isSend">
          <el-select v-model="form.isSend" placeholder="是否发货" size="small" clearable :disabled="isUpdate">
            <el-option label="未发货" :value="0" />
            <el-option label="已发货" :value="1" />
            <el-option label="部分发货" :value="2" />
            <el-option label="超发" :value="3" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否结账" prop="isBill">
          <el-select v-model="form.isBill" placeholder="是否结账" size="small" clearable :disabled="isUpdate">
            <el-option label="未结账" :value="0" />
            <el-option label="已结账" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="身高" prop="height">
          <el-input v-model="form.height" placeholder="请输入身高" />
        </el-form-item>
        <el-form-item label="体重" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入体重" />
        </el-form-item>
        <el-form-item label="体温(摄氏度)" prop="temperature">
          <el-input v-model="form.temperature" placeholder="请输入体温(摄氏度)" />
        </el-form-item>
        <el-form-item label="血压BP" prop="bp">
          <el-input v-model="form.bp" placeholder="请输入血压BP" />
        </el-form-item>
        <el-form-item label="脉搏(bmp)" prop="bmp">
          <el-input v-model="form.bmp" placeholder="请输入脉搏(bmp)" />
        </el-form-item>
        <el-form-item label="呼吸" prop="breathe">
          <el-input v-model="form.breathe" placeholder="请输入呼吸" />
        </el-form-item>
        <el-form-item label="血氧饱和度" prop="bloodOxygen">
          <el-input v-model="form.bloodOxygen" placeholder="请输入血氧饱和度" />
        </el-form-item>
        <el-form-item label="末次月经" prop="lastMenstruation">
          <el-input v-model="form.lastMenstruation" placeholder="请输入末次月经" />
        </el-form-item>
        <el-form-item label="药物过敏" prop="drugAllergy">
          <el-input v-model="form.drugAllergy" placeholder="请输入药物过敏" />
        </el-form-item>
        <el-form-item label="食物过敏" prop="foodAllergy">
          <el-input v-model="form.foodAllergy" placeholder="请输入食物过敏" />
        </el-form-item>
        <el-form-item label="非药物过敏" prop="undrugAllergy">
          <el-input v-model="form.undrugAllergy" placeholder="请输入非药物过敏" />
        </el-form-item>
        <el-form-item label="警示" prop="alertMark">
          <el-input v-model="form.alertMark" placeholder="请输入警示" />
        </el-form-item>
        <el-form-item label="病史" prop="medicalBg">
          <el-input v-model="form.medicalBg" placeholder="请输入病史" />
        </el-form-item>
        <el-form-item label="其它" prop="ext">
          <el-input v-model="form.ext" placeholder="请输入其它" />
        </el-form-item>
        <el-form-item label="医生诊断" prop="diagnoseContent">
          <el-input v-model="form.diagnoseContent" placeholder="请输入医生诊断" />
        </el-form-item>
        <el-form-item label="状态" prop="isValid">
          <el-input v-model="form.isValid" placeholder="请输入状态" />
        </el-form-item>
        <el-form-item label="最后更新时间" prop="synTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.synTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择最后更新时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { treeselect } from '@/api/system/dept'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { addQueryParam, getQueryParam } from "@/api/order/head";
import { listHead, getHead, delHead, addHead, updateHead, exportHead } from "@/api/sundry/head";

export default {
  name: "Sundry",
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 处方单表格数据
      headList: [],
      // 弹出层标题
      title: "",
      // 开单诊所
      deptOptions: undefined,
      // 修改操作禁用一些输入
      isUpdate: false,
      // 是否显示弹出层
      open: false,
      valueConsistsOf: 'ALL',
      // 查询参数
      queryParams: {
        deptIds: undefined,
        pageNum: 1,
        pageSize: 10,
        diagnoseId: undefined,
        orderType: undefined,
        encounterId: undefined,
        diagnoseCode: undefined,
        diagnoseCreatedAt: undefined,
        deptCode: undefined,
        deptName: undefined,
        doctorCode: undefined,
        doctorName: undefined,
        patientCode: undefined,
        patientName: undefined,
        gender: undefined,
        dob: undefined,
        auditorId: undefined,
        auditorName: undefined,
        auditorTime: undefined,
        auditStatus: undefined,
        isAudit: undefined,
        auditContent: undefined,
        isEquipStr: undefined,
        isSendStr: undefined,
        isBillStr: undefined,
        isEquip: undefined,
        isSend: undefined,
        isBill: undefined,
        age: undefined,
        height: undefined,
        weight: undefined,
        temperature: undefined,
        bp: undefined,
        bmp: undefined,
        breathe: undefined,
        bloodOxygen: undefined,
        lastMenstruation: undefined,
        drugAllergy: undefined,
        foodAllergy: undefined,
        undrugAllergy: undefined,
        alertMark: undefined,
        medicalBg: undefined,
        ext: undefined,
        diagnoseContent: undefined,
        isValid: undefined,
        synTime: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        diagnoseId: [
          { required: true, message: "处方单号不能为空", trigger: "blur" }
        ],
        orderType: [
          { required: true, message: "单据类型，1 处方 2 杂项不能为空", trigger: "blur" }
        ],
        encounterId: [
          { required: true, message: "就诊号不能为空", trigger: "blur" }
        ],
        diagnoseCode: [
          { required: true, message: "hms处方Id不能为空", trigger: "blur" }
        ],
        deptCode: [
          { required: true, message: "开单诊所不能为空", trigger: "blur" }
        ],
        doctorCode: [
          { required: true, message: "医生编码不能为空", trigger: "blur" }
        ],
        patientCode: [
          { required: true, message: "病案号不能为空", trigger: "blur" }
        ],
        gender: [
          { required: true, message: "性别（1男 2女 3 未知）不能为空", trigger: "blur" }
        ],
        dob: [
          { required: true, message: "出生日期不能为空", trigger: "blur" }
        ],
        auditorId: [
          { required: true, message: "审核人ID不能为空", trigger: "blur" }
        ],
        isAudit: [
          { required: true, message: "是否需要审核（0 不需要审核 1 需要审核 ）不能为空", trigger: "blur" }
        ],
        isEquipStr: [
          { required: true, message: "是否配货（0 否  1 是 2 部分配 3 超配）不能为空", trigger: "blur" }
        ],
        isSendStr: [
          { required: true, message: "是否发货（0 否  1 是 2 部分发 3 超发 ）不能为空", trigger: "blur" }
        ],
        isBillStr: [
          { required: true, message: "是否结账（0 否  1 是  ）不能为空", trigger: "blur" }
        ],
        isValid: [
          { required: true, message: "状态（0正常 1关闭）不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.setQueryParams();
    this.getTreeselect();
  },
  methods: {
    /** 回显查询条件 */
    setQueryParams() {
      getQueryParam().then(resp => {
        this.queryParams = resp.data;
        this.queryParams.synTime = resp.data.synTime && dayjs(resp.data.synTime).format('YYYY-MM-DD');
        this.queryParams.auditorTime = resp.data.auditorTime && dayjs(resp.data.auditorTime).format('YYYY-MM-DD');
        this.queryParams.diagnoseCreatedAt = resp.data.diagnoseCreatedAt && dayjs(resp.data.diagnoseCreatedAt).format('YYYY-MM-DD');
        this.queryParams.isEquipStr = resp.data.isEquipStr && resp.data.isEquipStr.split(',').map(Number);
        this.queryParams.isBillStr = resp.data.isBillStr && resp.data.isBillStr.split(',').map(Number);
        this.queryParams.isSendStr = resp.data.isSendStr && resp.data.isSendStr.split(',').map(Number);
        this.queryParams.deptIds = resp.data.deptIds && resp.data.deptIds.split(',').map(Number);
        this.queryParams.pageNum = 1;
        this.queryParams.pageSize = 10;
        delete this.queryParams.params;

        this.getList();
      })
    },
    /** 查询处方单列表 */
    getList() {
      this.loading = true;

      this.$nextTick(() => {
        this.$refs.patientCodeRef.focus()
      })

      const listHeadParams = {...this.queryParams};

      if(listHeadParams.isEquipStr && listHeadParams.isEquipStr.length > 0) {
        listHeadParams.isEquipStr = listHeadParams.isEquipStr.join(',');
      } else {
        listHeadParams.isEquipStr = ''
      }

      if(listHeadParams.isBillStr && listHeadParams.isBillStr.length > 0) {
        listHeadParams.isBillStr = listHeadParams.isBillStr.join(',');
      } else {
        listHeadParams.isBillStr = ''
      }

      if(listHeadParams.isSendStr && listHeadParams.isSendStr.length > 0) {
        listHeadParams.isSendStr = listHeadParams.isSendStr.join(',');
      } else {
        listHeadParams.isSendStr = ''
      }

      if(listHeadParams.deptIds && listHeadParams.deptIds.length > 0) {
        listHeadParams.deptIds = listHeadParams.deptIds.join(',');
      } else {
        listHeadParams.deptIds = ''
      }

      listHead(listHeadParams).then(response => {
        this.queryParams.patientCode = '';
        this.headList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询诊所下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        // 获取selectTree所需数据
        this.deptOptions = this.handleTree(response.data, "deptId");
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        diagnoseId: undefined,
        orderType: undefined,
        encounterId: undefined,
        diagnoseCode: undefined,
        diagnoseCreatedAt: undefined,
        deptCode: undefined,
        deptName: undefined,
        doctorCode: undefined,
        doctorName: undefined,
        patientCode: undefined,
        patientName: undefined,
        gender: undefined,
        dob: undefined,
        auditorId: undefined,
        auditorName: undefined,
        auditorTime: undefined,
        auditStatus: undefined,
        isAudit: undefined,
        auditContent: undefined,
        isEquip: undefined,
        isSend: undefined,
        isBill: undefined,
        age: undefined,
        height: undefined,
        weight: undefined,
        temperature: undefined,
        bp: undefined,
        bmp: undefined,
        breathe: undefined,
        bloodOxygen: undefined,
        lastMenstruation: undefined,
        drugAllergy: undefined,
        foodAllergy: undefined,
        undrugAllergy: undefined,
        alertMark: undefined,
        medicalBg: undefined,
        ext: undefined,
        diagnoseContent: undefined,
        isValid: undefined,
        synTime: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.resetForm("form");
    },
    /** 保存查询条件 */
    saveQuery() {
      const listHeadParams = {...this.queryParams};

      if(listHeadParams.isEquipStr && listHeadParams.isEquipStr.length > 0) {
        listHeadParams.isEquipStr = listHeadParams.isEquipStr.join(',');
      } else {
        listHeadParams.isEquipStr = ''
      }

      if(listHeadParams.isBillStr && listHeadParams.isBillStr.length > 0) {
        listHeadParams.isBillStr = listHeadParams.isBillStr.join(',');
      } else {
        listHeadParams.isBillStr = ''
      }

      if(listHeadParams.isSendStr && listHeadParams.isSendStr.length > 0) {
        listHeadParams.isSendStr = listHeadParams.isSendStr.join(',');
      } else {
        listHeadParams.isSendStr = ''
      }

      if(listHeadParams.deptIds && listHeadParams.deptIds.length > 0) {
        listHeadParams.deptIds = listHeadParams.deptIds.join(',');
      } else {
        listHeadParams.deptIds = ''
      }

      addQueryParam(listHeadParams).then(resp => {
        this.$message.success('查询条件保存成功');
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加处方单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getHead(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改处方单";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateHead(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addHead(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除处方单编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delHead(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有处方单数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportHead(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    /** 配/发药按钮操作 */
    handleSend(row) {
      this.$router.push(`/order/sundry/detail/${row.id}`);
    },
  }
};
</script>

<style lang="scss" scoped>
  .mod-selectTree-wrap {
    position: relative;
    display: inline-block;
    width: 402px;
    margin-top: 2px;
    line-height: 14px;
    font-size: 13px;
    vertical-align: top;
  }
  .font-error-color {
    font-weight: bold!important;
    color: #eb2323!important;
  }
</style>

<style lang="scss">
  .vue-treeselect__control {
    height: 30px!important;
    border-radius: 4px!important;
    border-color: #DCDFE6!important;
  }
  .vue-treeselect__placeholder {
    line-height: 30px!important;
  }
</style>
